#pragma once
#include"Define.h"
#include"Basket.h"
#include<deque>
#include<string>
using namespace std;
class ObjectList{
	public:
		struct _object
		{
			float x, y;//Toa do diem (x,y)
			int iType; //Loai doi tuong 1. trung - 0.Chat thai
		};

		typedef deque <_object*> _sObject;//Danh sach cac doi tuong
		_sObject Object;

		public:
		//Hien thi doi tuong
		void display()
		{
			for (_sObject::iterator i = Object.begin(); i != Object.end(); i++)
			{
				glPushMatrix();
				glColor3f(1, 1, 1);
				glTranslatef((*i)->x, (*i)->y, 0);
				glTranslatef(-(*i)->x, -(*i)->y, 0);

				if((*i)->iType==0){
					DrawTexture((*i)->x, (*i)->y, EGG, Textures[EGG].width/3 , Textures[EGG].height/3);
				}else{
					DrawTexture((*i)->x, (*i)->y, SHIT, Textures[SHIT].width/3, Textures[SHIT].height/3);
				}
				glPopMatrix();
				glEnd();
			}
		}
		//Timer cho doi tuong
		void timer()
		{
			//Hien thi doi tung roi xuong 
			for (_sObject::iterator i = Object.begin(); i != Object.end(); i++)
			{
				if(((*i)->y)>-HEIGHT/2+50)
				{
					(*i)->y -= fSpeed;
				}
			
			
			}
			//Thuc hien kiem tra doi tuong
			for (_sObject::iterator i = Object.begin(); i != Object.end(); i++)
			{
					if(((*i)->y)<-HEIGHT/2+100){
						//Neu doi tuong roi vao trong gio hung
						if(((*i)->x>fX) && ((*i)->y <fY)
							&& (((*i)->x +Textures[EGG].width/3 )  < fX+Textures[BASKET].width)
							&& (((*i)->y -Textures[EGG].height/3) < (fY-Textures[BASKET].height)) ){
								if((*i)->iType== 0){//Doi tuong roi vao gio hung la trung
									iScore++;
								}else{//Di tuong roi vao gio hung la chat thai
									iShit ++;
								}
								 //Huy vung nho doi tuongva loai khoi danh sach
								delete *i;
								Object.erase(i);
								break;
							}
						}
					//Kiem tra neu trung roi ra ngoai gio
					if(((*i)->y)<-HEIGHT/2+75){
						if((*i)->iType== 0)
							{
								iBrokenEggs ++;
							}
							delete *i;
							Object.erase(i);
							break;
					}
				}
				
		}

	//Gia cam san xuat
	void  produce(const float x, const float y,const int iType)
	{
		_object* Temp = new _object;
		Temp->x = x;
		Temp->y = y;
		Temp->iType = iType;
		Object.push_back(Temp);
	}
};


